package com.example.provider.service;

/**
 * @Author: banban
 * @Desctription: TODO
 * @Date: Created in 2023/12/8 16:36
 * @Version: 1.0
 */
import com.alibaba.dubbo.config.annotation.Service;
import com.example.imterface.entity.Product;
import com.example.imterface.service.ProductService;
import com.example.imterface.util.ResultVOUtil;
import com.example.imterface.vo.ResultVO;
import com.example.provider.mapper.ProductMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Service(timeout = 1000,retries = 4)
@Component
public class ProductServiceImpl implements ProductService {
    @Autowired
    private ProductMapper productMapper;
    @Override
    public ResultVO getProductById(Integer id) {
        System.out.println("---------getProductById-----------");
        try{
            Thread.sleep(3000);
        }catch (Exception e){
            e.printStackTrace();
        }
        Product product=productMapper.selectById(id);
        return ResultVOUtil.success(product);
    }
    @Override
    public ResultVO saveProduct(Product product) {
        int addNum=productMapper.insert(product);
        if(addNum<=0){
            return ResultVOUtil.error(400,"添加商品失败");
        }else{
            Map<String,Object>res=new HashMap<>();
            res.put("addNum",addNum);
            res.put("id",product.getPid());
            return ResultVOUtil.success(res);
        }
    }
}

